package com.viphuli.fragment;

import android.widget.EditText;
import butterknife.Bind;
import butterknife.OnClick;

import com.loopj.android.http.RequestParams;
import com.offroader.utils.StringUtils;
import com.offroader.utils.ViewUtils;
import com.viphuli.app.R;
import com.viphuli.common.AccessTokenKeeper;
import com.viphuli.http.ApiRequest;
import com.viphuli.http.bean.PageBaseBean;

/**
 * 意见反馈
 * 
 * @author li.li
 *
 */
public class AccountFeedbackFragment extends BaseProgressFragment {

	@Bind(R.id.id_account_feedback_text)
	protected EditText feedbackText;

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_account_feedback;
	}

	@Override
	protected void initParams() {

	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initData() {

	}

	@OnClick(R.id.id_account_feedback_btn)
	public void submit() {
		String feedback = feedbackText.getText().toString();

		if (StringUtils.isBlank(feedback)) {
			ViewUtils.toast(R.string.tip_feedback_empty);
			return;
		}

		//网络请求
		AccessTokenKeeper token = AccessTokenKeeper.readAccessToken(getActivity());

		if (token.isLogin()) {

			RequestParams params = new RequestParams();
			params.put("uid", token.getOpenId());
			params.put("content", feedback);

			ApiRequest.accountFeedback.request(this, params);

		} else {
			AccountLoginFragment.goWithConfirm(getActivity());
		}
	}
	
	@Override
	public void onRequestResonse(PageBaseBean page) {
		if (isAdded())
			caller.finish();
	}

}
